<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="" onsubmit="return re()">
		<input type="text" name="username" />
		<input type="submit" value="提交" />
	</form>
</body>
<script type="text/javascript">
    function re(){
    	var inp = document.getElementsByTagName('input');
	if(inp[0].value == ''){
		alert('不能为空');
		return false;
    }
}

onload = function(){
	alert('1');
}
alert('2');
</script>
</html>